package heap_sort

import "learning/gooop/sorting"

type tHeapSort struct {
}

func newHeapSort() sorting.ISorter {
	return &tHeapSort{}
}


func (me *tHeapSort) Sort(data []interface{}, comparator sorting.CompareFunction) []interface{} {
	heap := newArrayHeap(comparator)
	for _,it := range data {
		heap.Push(it)
	}

	for i,_ := range data {
		e,v := heap.Pop()
		if e == nil {
			data[i] = v
		} else {
			panic(e)
		}
	}

	return data
}


var HeapSort = newHeapSort()